home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / cheekyms.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  217 lines

  1. /*************************************************************************
  2.  Universal Cheeky Mouse Driver
  3.  (c)Lee Taylor May 1998, All rights reserved.
  4.  
  5.  For use only in offical Mame releases.
  6.  Not to be distrabuted as part of any commerical work.
  7. ***************************************************************************
  8. Functions to emulate the video hardware of the machine.
  9. ***************************************************************************/
  10.  
  11. #include "driver.h"
  12. #include "vidhrdw/generic.h"
  13.  
  14.  
  15. static int flipscreen = -1;
  16. static int redraw_man = 0;
  17. static int man_scroll = -1;
  18. static int sprites[0x20];
  19. static int char_palette = 0;
  20.  
  21.  
  22. void cheekyms_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  23. {
  24.     int i,j,bit;
  25.  
  26.     for (i = 0; i < 3; i++)
  27.     {
  28.         const unsigned char* color_prom_save = color_prom;
  29.  
  30.         /* lower nibble */
  31.         for (j = 0;j < Machine->drv->total_colors/6;j++)
  32.         {
  33.             /* red component */
  34.             bit = (color_prom[0] >> 0) & 0x01;
  35.             *(palette++) = 0xff * bit;
  36.             /* green component */
  37.             bit = (color_prom[0] >> 1) & 0x01;
  38.             *(palette++) = 0xff * bit;
  39.             /* blue component */
  40.             bit = (color_prom[0] >> 2) & 0x01;
  41.             *(palette++) = 0xff * bit;
  42.  
  43.             color_prom++;
  44.         }
  45.  
  46.         color_prom = color_prom_save;
  47.  
  48.         /* upper nibble */
  49.         for (j = 0;j < Machine->drv->total_colors/6;j++)
  50.         {
  51.             /* red component */
  52.             bit = (color_prom[0] >> 4) & 0x01;
  53.             *(palette++) = 0xff * bit;
  54.             /* green component */
  55.             bit = (color_prom[0] >> 5) & 0x01;
  56.             *(palette++) = 0xff * bit;
  57.             /* blue component */
  58.             bit = (color_prom[0] >> 6) & 0x01;
  59.             *(palette++) = 0xff * bit;
  60.  
  61.             color_prom++;
  62.         }
  63.     }
  64. }
  65.  
  66.  
  67. WRITE_HANDLER( cheekyms_sprite_w )
  68. {
  69.     sprites[offset] = data;
  70. }
  71.  
  72.  
  73. WRITE_HANDLER( cheekyms_port_40_w )
  74. {
  75.     static int last_dac = -1;
  76.  
  77.     /* The lower bits probably trigger sound samples */
  78.  
  79.     if (last_dac != (data & 0x80))
  80.     {
  81.         last_dac = data & 0x80;
  82.  
  83.         DAC_data_w(0, last_dac ? 0x80 : 0);
  84.     }
  85. }
  86.  
  87.  
  88. WRITE_HANDLER( cheekyms_port_80_w )
  89. {
  90.     int new_man_scroll, new_char_palette, new_flipscreen;
  91.  
  92.     /* Bits 0-1 Sound enables, not sure which bit is which */
  93.  
  94.     /* Bit 2 is interrupt enable */
  95.     interrupt_enable_w(offset, data & 0x04);
  96.  
  97.     /* Bit 3-5 Man scroll amount */
  98.     new_man_scroll = (data >> 3) & 0x07;
  99.     if (man_scroll != new_man_scroll)
  100.     {
  101.         man_scroll = new_man_scroll;
  102.         redraw_man = 1;
  103.     }
  104.  
  105.     /* Bit 6 is palette select (Selects either 0 = PROM M8, 1 = PROM M9) */
  106.     new_char_palette = (data >> 2) & 0x10;
  107.     if (char_palette != new_char_palette)
  108.     {
  109.         char_palette = new_char_palette;
  110.         memset(dirtybuffer, 1, videoram_size);
  111.     }
  112.  
  113.     /* Bit 7 is screen flip */
  114.     new_flipscreen = (data >> 7) & 0x01;
  115.     if (flipscreen != new_flipscreen)
  116.     {
  117.         flipscreen = new_flipscreen;
  118.         memset(dirtybuffer, 1, videoram_size);
  119.     }
  120. }
  121.  
  122.  
  123.  
  124. /***************************************************************************
  125.  
  126.   Draw the game screen in the given osd_bitmap.
  127.   Do NOT call osd_update_display() from this function, it will be called by
  128.   the main emulation engine.
  129.  
  130. ***************************************************************************/
  131. void cheekyms_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  132. {
  133.     int offs;
  134.  
  135.     fillbitmap(bitmap,Machine->pens[0],&Machine->drv->visible_area);
  136.  
  137.     /* Draw the sprites first, because they're supposed to appear below
  138.        the characters */
  139.     for (offs = 0; offs < sizeof(sprites); offs += 4)
  140.     {
  141.         int v1, sx, sy, col, code;
  142.  
  143.         v1  = sprites[offs + 0];
  144.         sy  = sprites[offs + 1];
  145.         sx  = 256 - sprites[offs + 2];
  146.         col = (sprites[offs + 3] & 0x07);
  147.  
  148.         if (!(sprites[offs + 3] & 0x08)) continue;
  149.  
  150.         code = (~v1 << 1) & 0x1f;
  151.         if (v1 & 0x80)
  152.         {
  153.             drawgfx(bitmap,Machine->gfx[1],
  154.                     code + (flipscreen ^ 1),
  155.                     col,
  156.                     0,0,
  157.                     sx,sy,
  158.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  159.         }
  160.         else
  161.         {
  162.             drawgfx(bitmap,Machine->gfx[1],
  163.                     code + 0x20,
  164.                     col,
  165.                     0,0,
  166.                     sx,sy,
  167.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  168.  
  169.             drawgfx(bitmap,Machine->gfx[1],
  170.                     code + 0x21,
  171.                     col,
  172.                     0,0,
  173.                     sx + 8*(v1 & 2),sy + 8*(~v1 & 2),
  174.                     &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  175.         }
  176.     }
  177.  
  178.     /* for every character in the Video RAM, check if it has been modified */
  179.     /* since last time and update it accordingly. */
  180.     for (offs = videoram_size - 1;offs >= 0;offs--)
  181.     {
  182.         int sx,sy,man_area;
  183.  
  184.         sx = offs % 32;
  185.         sy = offs / 32;
  186.  
  187.         man_area = ((sy >= (6  - flipscreen)) &&
  188.                     (sy <= (26 - flipscreen)) &&
  189.                     (sx >=  8)                &&
  190.                     (sx <= 12));
  191.  
  192.         if (dirtybuffer[offs] ||
  193.             (redraw_man && man_area))
  194.         {
  195.             dirtybuffer[offs] = 0;
  196.  
  197.             if (flipscreen)
  198.             {
  199.                 sx = 31 - sx;
  200.                 sy = 31 - sy;
  201.             }
  202.  
  203.             drawgfx(tmpbitmap,Machine->gfx[0],
  204.                     videoram[offs],
  205.                     0 + char_palette,
  206.                     flipscreen,flipscreen,
  207.                     8*sx, 8*sy - (man_area ? man_scroll : 0),
  208.                     &Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  209.         }
  210.     }
  211.  
  212.     redraw_man = 0;
  213.  
  214.     /* copy the temporary bitmap to the screen over the sprites */
  215.     copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_PEN,Machine->pens[4*char_palette]);
  216. }
  217.